﻿using System;
using Core.Library;
using DataObject;
using DataObject.Image;
using DataObject.Product;

public partial class Controls_Product_Detail : System.Web.UI.UserControl
{
    protected int CategoryId;
    protected int ProductId;
    protected int Type;
    protected string Name;
    protected string Description;
    protected string Content;
    protected string Images;
    protected string UnitPrice;
    protected string SpecialPrice;

    protected void Page_Load(object sender, EventArgs e)
    {
        ProductId = Utils.GetIdFromRequestString(Utils.ProductId, 0);

        //Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "denhongphuc",
        //    "<script>listRelatedProduct(" + CategoryId + ", " + ProductId + ", " + (int)CategoryType.Product + ", " + SettingValues.PageIndex + ");</script>");

        if (!IsPostBack)
            ProductDetail();    
    }   

    private void ProductDetail()
    {        
        try
        {
            var o = ProductController.Product_GetById(ProductId);
            if (o != null)
            {
                Name = string.Format("{0} - {1}", o.Code, o.Name);
                Description = o.Description;
                Content = o.Content;
                Images = o.Images;
                UnitPrice = Utils.FormatPrice(ConvertUtility.ToDecimal(o.UnitPrice));
                SpecialPrice = Utils.FormatPrice(ConvertUtility.ToDecimal(o.SpecialPrice));
                CategoryId = o.CategoryId;
                Type = o.Type;

                //var lstImage = ImageController.Image_GetByProductId(ProductId);
                //if (lstImage != null && lstImage.Count > 0)
                //{
                //    rptImage.DataSource = lstImage;
                //    rptImage.DataBind();

                //    rptThumbImage.DataSource = lstImage;
                //    rptThumbImage.DataBind();
                //}

                Page.Title = string.Format(".: {0} - {1} {2} :.", o.Code, o.Name, Constants.SITE_TITLE);
            }
        }
        catch { }        
    }    
}